<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>rsde.m</title>
<link rel="stylesheet" type="text/css" href="../../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>model&nbsp;</span>=&nbsp;<span class=defun_name>rsde</span>(<span class=defun_in>X,options</span>)<br>
<span class=h1>%&nbsp;RSDE&nbsp;Reduced&nbsp;Set&nbsp;Density&nbsp;Estimator.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;=&nbsp;rsde(X,options)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;This&nbsp;function&nbsp;implements&nbsp;the&nbsp;Reduced&nbsp;Set&nbsp;Density&nbsp;Estimator&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;[Girol03]&nbsp;which&nbsp;provides&nbsp;kernel&nbsp;density&nbsp;estimate&nbsp;optimal&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;in&nbsp;the&nbsp;L2&nbsp;sense.&nbsp;The&nbsp;density&nbsp;is&nbsp;modeled&nbsp;as&nbsp;the&nbsp;weighted&nbsp;sum&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;of&nbsp;Gaussians&nbsp;(RBF&nbsp;kernel)&nbsp;centered&nbsp;in&nbsp;selected&nbsp;subset&nbsp;of&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;training&nbsp;data.&nbsp;</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;The&nbsp;estimation&nbsp;is&nbsp;expressed&nbsp;as&nbsp;a&nbsp;special&nbsp;instance&nbsp;of&nbsp;the</span><br>
<span class=help>%&nbsp;&nbsp;Quadratic&nbsp;Programming&nbsp;task&nbsp;(see&nbsp;'help&nbsp;gmnp').</span><br>
<span class=help>%&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;<span class=help_field>Input:</span></span><br>
<span class=help>%&nbsp;&nbsp;X&nbsp;[dim&nbsp;x&nbsp;num_data]&nbsp;Input&nbsp;data&nbsp;sample.</span><br>
<span class=help>%&nbsp;&nbsp;options&nbsp;[struct]&nbsp;Control&nbsp;parameters:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.arg&nbsp;[1x1]&nbsp;Standard&nbsp;deviation&nbsp;of&nbsp;the&nbsp;Gaussian&nbsp;kernel.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.solver&nbsp;[string]&nbsp;QP&nbsp;solver&nbsp;(see&nbsp;'help&nbsp;gmnp');&nbsp;'imdm'&nbsp;default.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Output:</span></span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;[struct]&nbsp;Output&nbsp;density&nbsp;model:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.Alpha&nbsp;[nsv&nbsp;x&nbsp;1]&nbsp;Weights&nbsp;of&nbsp;the&nbsp;kernel&nbsp;functions.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.sv.X&nbsp;[dim&nbsp;x&nbsp;nsv]&nbsp;Selected&nbsp;centers&nbsp;of&nbsp;kernel&nbsp;functions.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.nsv&nbsp;[1x1]&nbsp;Number&nbsp;of&nbsp;selected&nbsp;centers.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.options.arg&nbsp;=&nbsp;options.arg.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.options.ker&nbsp;=&nbsp;'rbf'</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;.stat&nbsp;[struct]&nbsp;Statistics&nbsp;about&nbsp;optimization:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.access&nbsp;[1x1]&nbsp;Number&nbsp;of&nbsp;requested&nbsp;columns&nbsp;of&nbsp;matrix&nbsp;H.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.t&nbsp;[1x1]&nbsp;Number&nbsp;of&nbsp;iterations.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.UB&nbsp;[1x1]&nbsp;Upper&nbsp;bound&nbsp;on&nbsp;the&nbsp;optimal&nbsp;value&nbsp;of&nbsp;criterion.&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.LB&nbsp;[1x1]&nbsp;Lower&nbsp;bound&nbsp;on&nbsp;the&nbsp;optimal&nbsp;value&nbsp;of&nbsp;criterion.&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.LB_History&nbsp;[1x(t+1)]&nbsp;LB&nbsp;with&nbsp;respect&nbsp;to&nbsp;iteration.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.UB_History&nbsp;[1x(t+1)]&nbsp;UB&nbsp;with&nbsp;respect&nbsp;to&nbsp;iteration.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NA&nbsp;[1x1]&nbsp;Number&nbsp;of&nbsp;non-zero&nbsp;entries&nbsp;in&nbsp;solution.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;<span class=help_field>Example:</span></span><br>
<span class=help>%&nbsp;&nbsp;gnd&nbsp;=&nbsp;struct('Mean',[-2&nbsp;3],'Cov',[1&nbsp;0.5],'Prior',[0.4&nbsp;0.6]);</span><br>
<span class=help>%&nbsp;&nbsp;sample&nbsp;=&nbsp;gmmsamp(&nbsp;gnd,&nbsp;1000&nbsp;);</span><br>
<span class=help>%&nbsp;&nbsp;figure;&nbsp;hold&nbsp;on;&nbsp;ppatterns(sample.X);</span><br>
<span class=help>%&nbsp;&nbsp;plot([-4:0.1:8],&nbsp;pdfgmm([-4:0.1:8],gnd),'r');</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;=&nbsp;rsde(sample.X,struct('arg',0.7));</span><br>
<span class=help>%&nbsp;&nbsp;x&nbsp;=&nbsp;linspace(-4,8,100);</span><br>
<span class=help>%&nbsp;&nbsp;plot(x,kernelproj(x,model),'g');&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;ppatterns(model.sv.X,'ob',13);</span><br>
<span class=help>%&nbsp;&nbsp;Reduction&nbsp;=&nbsp;model.nsv/size(sample.X,2)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;KERNELPROJ,&nbsp;EMGMM,&nbsp;MLCGMM,&nbsp;GMNP.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2005,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;24-jan-2005,&nbsp;VF,&nbsp;Fast&nbsp;QP&nbsp;solver&nbsp;(GMNP)&nbsp;was&nbsp;used&nbsp;instead&nbsp;of&nbsp;QUADPROG.</span><br>
<span class=help1>%&nbsp;17-sep-2004,&nbsp;VF,&nbsp;revised</span><br>
<br>
<br>
<hr>
<span class=comment>%&nbsp;Input&nbsp;arguments</span><br>
<span class=comment>%-------------------------------------------------------</span><br>
[dim,num_data]&nbsp;=&nbsp;size(X);<br>
<span class=keyword>if</span>&nbsp;<span class=stack>nargin</span>&nbsp;&lt;&nbsp;2,&nbsp;options&nbsp;=&nbsp;[];&nbsp;<span class=keyword>else</span>&nbsp;options&nbsp;=&nbsp;c2s(options);&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'arg'</span>),&nbsp;options.arg&nbsp;=&nbsp;1;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>if</span>&nbsp;~isfield(options,<span class=quotes>'solver'</span>),&nbsp;options.solver&nbsp;=&nbsp;<span class=quotes>'imdm'</span>;&nbsp;<span class=keyword>end</span><br>
<br>
options.ker&nbsp;=&nbsp;<span class=quotes>'rbf'</span>;<br>
<br>
<span class=comment>%&nbsp;Solve&nbsp;associted&nbsp;QP&nbsp;task</span><br>
<span class=comment>%-------------------------------------------------------</span><br>
<br>
<span class=comment>%G2h&nbsp;=&nbsp;1/((2*pi)^(dim/2)*(sqrt(2)*options.arg)^dim)*...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;kernel(X,options.ker,options.arg*sqrt(2));</span><br>
<span class=comment>%Ph&nbsp;=&nbsp;-1/((2*pi)^(dim/2)*options.arg^dim)*...</span><br>
<span class=comment>%&nbsp;&nbsp;&nbsp;&nbsp;sum(kernel(X,options.ker,options.arg),2)/num_data;</span><br>
G2h&nbsp;=&nbsp;kernel(X,options.ker,options.arg*sqrt(2))/sqrt(2);<br>
Ph&nbsp;=&nbsp;-sum(kernel(X,options.ker,options.arg),2)/num_data;<br>
<br>
[Alpha,fval,stat]=&nbsp;gmnp(G2h,Ph,options);<br>
&nbsp;<br>
inx&nbsp;=&nbsp;find(Alpha&nbsp;&gt;&nbsp;0);<br>
model.Alpha&nbsp;=&nbsp;Alpha(inx)/((2*pi)^(dim/2)*options.arg^dim);<br>
model.b&nbsp;=&nbsp;0;<br>
model.sv.X&nbsp;=&nbsp;X(:,inx);<br>
model.nsv&nbsp;=&nbsp;length(inx);<br>
model.pr2&nbsp;=&nbsp;model.Alpha'*G2h(inx,inx)*model.Alpha;<br>
model.options&nbsp;=&nbsp;options;<br>
model.stat&nbsp;=&nbsp;stat;<br>
model.fun&nbsp;=&nbsp;<span class=quotes>'kernelproj'</span>;<br>
<br>
<span class=jump>return</span>;<br>
<span class=comment>%&nbsp;EOF</span><br>
</code>
